package router

import (
	"context"
	"fmt"
	"gdshop-font-api-go/app/request/OrderReq"
	"gdshop-font-api-go/app/service/OrderService"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/util/gconv"
	"github.com/gookit/event"
)

func regEventBus() {
	// 注册 eventBus ，解耦用 ，处理 下单
	event.On("SubmitQueue", event.ListenerFunc(func(e event.Event) error {
		fmt.Println("---------------------------SubmitQueue - EventBus --------------------------------------------------------")
		id := gconv.String(e.Get("Id"))
		body := e.Get("Body")
		fmt.Printf("handle Body: %s\n\n", body)
		/*var parames *OrderReq.Submit
		err := gconv.Struct(body, &parames)
		if err != nil {
			return err
		}
		jieguo := OrderService.SubmitEventBus(context.Background(), parames)
		g.Redis().Do("SETEX", "CheckSubmitOk:"+id, 6, jieguo)*/

		var parames *OrderReq.SubmitGroup
		err := gconv.Struct(body, &parames)
		if err != nil {
			return err
		}
		jieguo := OrderService.DoSubmitOrderGroup(context.Background(), parames)
		g.Redis().Do("SETEX", "CheckSubmitOk:"+id, 6, jieguo)

		return nil
	}), event.Normal)
}
